package com.stt.weather.design.factory;

import com.stt.weather.design.observer.WeatherObserver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 通知观察者工厂
 * 负责管理所有通知观察者实例
 */
@Component
public class NotificationFactory {
    
    private final Map<String, WeatherObserver> observerMap = new ConcurrentHashMap<>();

    public NotificationFactory(List<WeatherObserver> observers) {
        // 将所有观察者注册到Map中
        for (WeatherObserver observer : observers) {
            observerMap.put(observer.getType(), observer);
        }
    }
    
    /**
     * 获取指定类型的观察者
     * @param type 观察者类型
     * @return 观察者实例
     */
    public WeatherObserver getObserver(String type) {
        return observerMap.get(type);
    }
    
    /**
     * 获取所有已注册的观察者
     * @return 观察者列表
     */
    public List<WeatherObserver> getAllObservers() {
        return List.copyOf(observerMap.values());
    }
} 